// 05.03.12 - Matthew Brews - Original Creation.

#include "bomb.h"

#include "player.h"

CBomb::CBomb()
    : CWeapon(1, "weapons/bomb", ENT_WEAPON_BOMB),
    m_nExplodeRadius(1)

{
    getDisplayable()->setVisible(false);
}

bool CBomb::fire()
{
    if (CWeapon::fire())
    {
        int nHeight(0), nWidth(0), nDepth(0);
        CMap *pMap(CMapContainer::getInstance()->getCurrentMap());

        pMap->getTilePositionFromCoord(nHeight, nWidth, nDepth, 
                                       getX(), getY(), getZ(), 0);

        if (pMap->isValidTile(nHeight, nWidth, nDepth))
        {
            CTile *pTile(pMap->getTile(nHeight, nWidth, nDepth));

            //pTile->getDisplayable()->showBoundingBox();
            
            if (! pTile->isEntityInBlock(ENT_PROJECTILE_BOMB))
            {
                //CBombProjectile *pBomb = new CBombProjectile(
                //    getX(), getY() + 64.0f, getZ());
                CSound *pSound(CSoundManager::getInstance()->addSound(
                    "bomb_set.wav"));
                FMOD::Channel *pChannel(nullptr);
                pSound->createNewChannel(&pChannel);
                pChannel->setPaused(false);

                CBombProjectile *pBomb(new CBombProjectile(
                      getX(), getY() + 64.0f, getZ()));
                pTile->addEntityInBlock(pBomb);
                pBomb->setInMotion(true);
                pBomb->setVelocity(0.0f, 3.0f, 0.0f);
                pBomb->setOwner(this);
                //pBomb->getDisplayable()->showBoundingBox();

                dynamic_cast<CPlayer*>(
                    getOwner())->updateStatValue(
                    "bombs placed", 1);

                return true;
            }
        }
        // Could not fire, increase clip count
        setClipCount(getClipCount() + 1);
    }
    return false;

}

void CBomb::explode()
{
    //ToDo!
}

void CBomb::setDamage(float fDamage)
{
    m_fDamage = fDamage;
}

float CBomb::getDamage() const
{
    return m_fDamage;
}

void CBomb::setExplodeRadius(int nRadius)
{
    m_nExplodeRadius = nRadius;
}

int CBomb::getExplodeRadius() const
{
    return m_nExplodeRadius;
}